#include <iostream>
#include <signal.h>
using namespace std;

void Printf(const sigset_t& pending)
{
    for(int i = 31;i > 0;i--)
    {
        if(sigismember(&pending,i) == 1)
        {
            cout<<1;
        }
        else cout<<0;
    }
    cout<<endl;
}
void headler(int signal)
{
    cout<<"Signal received"<<endl;
}

int main()
{
    signal(2,headler);
    sigset_t block,oblock;

    //重置两个block表
    sigemptyset(&block);
    sigemptyset(&oblock);

    //设置屏蔽信号
    sigaddset(&block,2);

    //将信号设置进内核
    sigprocmask(SIG_BLOCK,&block,&oblock);

    sigset_t pending;
    int count = 0;
    while(true)
    {
        //打印pending表
        sigpending(&pending);
        Printf(pending);
        if(count == 10)
        {
            sigprocmask(SIG_SETMASK,&oblock,nullptr);
            cout<<"Unblock signal"<<endl;
        }
        count++;
        sleep(1);
    }
    return 0;
}